﻿#include "saveimgworker.h"
#include <QDir>
#include <QDebug>
SaveImgWorker::SaveImgWorker(QObject* parent) : QObject(parent)
{

}



SaveImgWorker::~SaveImgWorker()
{

}
void SaveImgWorker::Initialize()
{

}

void SaveImgWorker::start(CameraData m_cImageInfo)
{
	int nSave = 0;
	QString strPath = QDir::currentPath() + "/Pic";
	switch (m_cImageInfo.m_nIndex) {
	case 1:
		strPath += "/ccd1";
		break;
	case 2:
		strPath += "/ccd2";
		break;
    case 3:
        strPath += "/ccd3";
        break;
	}

	if (m_cImageInfo.m_nNGorOK == 0) {
		if (m_nSaveType % 10 == 1) {
			strPath += "/OK/";
			nSave++;
		}

	}
	else {
		if (m_nSaveType % 100 >= 10) {
			strPath += "/NG/";
			nSave++;
		}
		if (m_nSaveType % 1000 >= 100) {
			strPath += "/Abnormal/";
			nSave++;
		}

	}

	if (nSave == 0) {
		return;
	}
	QString path = QString("%1%2.bmp").arg(strPath).arg(m_nIndex);
	HalconCpp::WriteImage(m_cImageInfo.Hobj, "bmp", 0, path.toStdString().c_str());
	m_nIndex++;
}

